package com.whmskj.xjlhsc.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @BelongsProject: XJLHSC
 * @BelongsPackage: com.whmskj.xjlhsc.config
 * @Author: lk
 * @CreateTime: 2025-06-30
 * @Description: TODO
 * @Version: 1.0
 */
@Configuration
public class ThreadPollConfig {

    @Bean("ioIntensiveThreadPool")
    public ThreadPoolExecutor ioIntensiveThreadPool() {
        int cpuCores = Runtime.getRuntime().availableProcessors();
        return new ThreadPoolExecutor(
                cpuCores * 2,
                cpuCores * 4,
                60L,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(1000),  // 有界队列防止OOM
                new ThreadPoolExecutor.CallerRunsPolicy() // 拒绝策略
        );
    }
}
